<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
    <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
    <head>
    <title>Search</title>
    <link rel="stylesheet" href="lightning.css" type="text/css" />
    <script src="/sarissa/sarissa.js" type="text/javascript"></script>
    <script src="encoder.js" type="text/javascript"></script>
    <script type="text/javascript">
    function doSearch(){
            // HTML Entities Encoder Setup
            Encoder.EncodeType = "numerical";
            

	    // Get query from text box
	    var query = document.getElementById("query").value

	    // Show busy cursor
	    document.getElementById("thebod").style.cursor = "wait";

	    var xmlHttp = new XMLHttpRequest();
	    // specify HTTP method, file URL and 
	    // whether to use asynchronous loading
	    xmlHttp.open("GET", "/dave/blogger/swish-e.php?w="+query, true);
	    xmlHttp.onreadystatechange = function()
	    {
		    if(xmlHttp.readyState == 4){
			    var xmlDoc = xmlHttp.responseXML;
			    var results = xmlDoc.documentElement.getElementsByTagName("result");
			    html='&lt;h2&gt;Results for &lt;em&gt;&quot;'+query+'&quot;&lt;/em&gt;&lt;/h2&gt;';
			    for (var i = 0; i != results.length; i++){
				    var rank = results[i].getAttribute("rank");
				    var title = Encoder.htmlEncode( results[i].getAttribute("title") );
				    var href = results[i].getAttribute("href");
                                    var year = results[i].getAttribute("year");
                                    var month = results[i].getAttribute("month");
				    // format this result
				    html += '&lt;p&gt;&lt;span class="rank"&gt;['+year+'-'+month+']&lt;/span&gt; &lt;span class="title"&gt;&lt;a href="'+href+'#w='+query+'"&gt;'+title+'&lt;/a&gt;&lt;/span&gt;&lt;span class="size"&gt;'+"&lt;/span&gt;&lt;/p&gt;\n";
			    }
			    document.getElementById("results").innerHTML = html;
			    document.getElementById("debug").innerHTML = '';
			    // Show normal cursor
			    document.getElementById("thebod").style.cursor = "default";
			
		    }
	    }
	
	    // perform the actual request
	    xmlHttp.send(null);
    }
    </script>
    </head>
    <body id="thebod">
    <div id="searchbox">
    Search for documents containing the text:
    <form action="javascript:doSearch()" id="searchform">

    <input type="text" maxlength="48" size="32" id="query" />
    <input type="submit" value="Search" />
    </form>
    </div>
    <div id="results">
    <xsl:if test="results/query != &quot;&quot;">
      <h2>Results for <em>&quot;<xsl:value-of select="/results/query"/>&quot;</em></h2>
    </xsl:if> 
    <xsl:for-each select="/results/result">
      <p>
      <xsl:variable name="docpath"><xsl:value-of select="@href"/></xsl:variable>
      <xsl:variable name="qval"><xsl:value-of select="/results/query"/></xsl:variable>
      <span class="rank">[<xsl:value-of select="@year"/>-<xsl:value-of select="@month"/>]</span>
      <span class="title"><a href="{$docpath}#w={$qval}"><xsl:value-of select="@title"/></a></span>
      </p>
    </xsl:for-each>
    </div>
    <div id="debug">
    <xsl:if test="/results/error != &quot;&quot;">
      <xsl:for-each select="/results/error">
        <p class="error"><xsl:value-of select="/results/error"/></p>
      </xsl:for-each>
    </xsl:if> 
    </div>
    </body>
    </html>
    </xsl:template>
</xsl:stylesheet>
